﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BLL.Progect
{
    public class T_PUB_PROJECT
    {

        private readonly DALL.Progect.T_PUB_PROJECT dal = new DALL.Progect.T_PUB_PROJECT();

        /// <summary>
        /// 项目获得图片
        /// </summary>
        /// <param name="strids">项目id 如 id1,id2,</param>
        /// <returns></returns>
        public DataTable GetProgectImage(string strids)
        {
            string strarrid = "";
            if (strids.IndexOf(",") >= 0)
            {
                string[] strArry = strids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in strArry)
                {
                    strarrid = strarrid + string.Format("'{0}'", item) + ",";
                }
                if (strarrid.Length > 0)
                {
                    strarrid = strarrid.Substring(0, strarrid.Length - 1);
                }
            }
            else
            {
                strarrid = "'" + strids + "'";
            }

            string strWhere = string.Format(" and p.PROJECT_ID in ({0})", strarrid);
            return dal.GetProgectImage(strWhere);
        }

        public T_PUB_PROJECT()
        { }

        public List<Model.Progect.T_PUB_PROJECT> GetProjecList(string strID)
        {
            string strWhere = "";
            strWhere += string.Format(" and b.PROJECT_ID = '{0}' ", strID);
            return dal.GetProjectList(strWhere);
        }

        /// <summary>
        /// 添加项目
        /// </summary>
        /// <param name="model"></param>
        /// <param name="matralList"></param>
        public void AddProgect(Model.Progect.T_PUB_PROJECT model, IList<Model.Progect.T_PUB_PROJECTMATERIAL> matralList)
        {
            dal.AddProgect(model, matralList);
        }
        /// <summary>
        /// 项目编辑
        /// </summary>
        /// <param name="model"></param>
        /// <param name="matralList"></param>
        public void EditProgect(Model.Progect.T_PUB_PROJECT model, IList<Model.Progect.T_PUB_PROJECTMATERIAL> EditList, IList<Model.Progect.T_PUB_PROJECTMATERIAL> AddList)
        {
            dal.EditProgect(model, EditList, AddList);
        }
        /// <summary>
        /// 获得分类项目
        /// </summary>
        /// <param name="strTypeID"></param>
        /// <returns></returns>
        public DataSet GetListWithMateral(string strTypeID, string strBranchID)
        {
            BLL.SysManage.T_PUB_PROJECTTYPE progectBll = new SysManage.T_PUB_PROJECTTYPE();
            Model.SysManage.T_PUB_PROJECTTYPE typeModel = null;
            string strPath;
            if (strTypeID != "")
            {
                typeModel = progectBll.GetModel(Convert.ToInt32(strTypeID));
            }
            if (typeModel != null)
            {
                strPath = typeModel.IDPATH;

            }
            else
            {
                strPath = "0/";
            }

            string strWhere = " and p.FLAG=1";

            strWhere += string.Format(" and y.IDPATH like '%{0}%'", strPath);

            if (strBranchID != "")
            {
                strWhere = strWhere + string.Format("  and p.BRANCH_ID ='{0}'", strBranchID);
            }
            return dal.GetListWithMateral(strWhere);
        }
        public DataSet GetListWithMateralAndImage(string strTypeID, string strBranchID)
        {
            BLL.SysManage.T_PUB_PROJECTTYPE progectBll = new SysManage.T_PUB_PROJECTTYPE();
            Model.SysManage.T_PUB_PROJECTTYPE typeModel = null;
            string strPath;
            if (strTypeID != "")
            {
                typeModel = progectBll.GetModel(Convert.ToInt32(strTypeID));
            }
            if (typeModel != null)
            {
                strPath = typeModel.IDPATH;

            }
            else
            {
                strPath = "0/";
            }

            string strWhere = " and p.FLAG=1";

            strWhere += string.Format(" and y.IDPATH like '%{0}%'", strPath);

            if (strBranchID != "")
            {
                strWhere = strWhere + string.Format("  and p.BRANCH_ID ='{0}'", strBranchID);
            }
            string strImageWhere = " and T_PUB_PROJECT.FLAG=1";
            if (strBranchID != "")
            {
                strImageWhere = strImageWhere + string.Format("  and T_PUB_PROJECT.BRANCH_ID='{0}'",strBranchID);
            }
            if (strTypeID!="")
            {
                strImageWhere = strImageWhere + string.Format(" and T_PUB_PROJECT.PROJECTTYPE_ID in ( select PROJECTTYPE_ID from dbo.T_PUB_PROJECTTYPE where IDPATH like '%{0}%')", strPath);
            }
            return dal.GetListWithMateralAndImage(strWhere, strImageWhere);
        }

        public string GetstrIDs(string strID)
        {
            string strResout = "";

            return strResout;
        }

        public DataTable GetOrderProject(string strBranchID, string strIDS)
        {
            string strarrid = "";
            if (strIDS.IndexOf(",") >= 0)
            {
                string[] strArry = strIDS.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in strArry)
                {
                    strarrid = strarrid + string.Format("'{0}'", item) + ",";
                }
                if (strarrid.Length > 0)
                {
                    strarrid = strarrid.Substring(0, strarrid.Length - 1);
                }
            }
            else
            {
                strarrid = "'" + strIDS + "'";
            }

            // string strWhere = string.Format(" and   p.BRANCH_ID='{0}'  and p.PROJECT_ID in ({1})", strBranchID, strarrid);
            string strWhere = string.Format(" and p.PROJECT_ID in ({0})", strarrid);
            return dal.GetOrderProject(strWhere);
        }

        #region 获得文件项目
        public DataTable GetFileProgect(string strFileID)
        {
            string strWhere = string.Format(" where a.FILE_ID='{0}'", strFileID);
            return dal.GetProgect(strWhere);
        }
        #endregion

        #region  获得文件的主题婚礼
        public DataTable GetFileThem(string strFileID)
        {
            return dal.GetFileThem(strFileID);
        }
        #endregion

        /// <summary>
        /// 智能提示项目名称
        /// </summary>
        /// <param name="branch_id"></param>
        /// <returns></returns>
        public DataSet GetProjectName(int branch_id)
        {
            return dal.GetProjectName(branch_id);
        }

        public DataSet GetProjectName()
        {
            return dal.GetProjectName();
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Progect.T_PUB_PROJECT> GetModelListName(string strWhere)
        {
            return dal.GetListArrayName(strWhere);

        }

        #region  Method
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.Progect.T_PUB_PROJECT model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.Progect.T_PUB_PROJECT model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string PROJECT_ID)
        {

            return dal.Delete(PROJECT_ID);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Progect.T_PUB_PROJECT GetModel(string PROJECT_ID)
        {

            return dal.GetModel(PROJECT_ID);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Progect.T_PUB_PROJECT> GetModelList(string strWhere)
        {
            return dal.GetListArray(strWhere);

        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }
        #endregion  Method
    }
}
